package main;

import java.awt.Color;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.JTextField;
import javax.swing.text.Document;

public class textBox extends JTextField implements KeyListener{

	private static final long serialVersionUID = 1L;
	private int number;

	public textBox() {
		addKeyListener(this);
	}

	public textBox(String text) {
		super(text);
		addKeyListener(this);
	}

	public textBox(int columns) {
		super(columns);
		addKeyListener(this);
	}

	public textBox(String text, int columns) {
		super(text, columns);
		addKeyListener(this);
	}

	public textBox(Document doc, String text, int columns) {
		super(doc, text, columns);
		addKeyListener(this);
	}

	@Override
	public void keyPressed(KeyEvent e) {
		
	}

	@Override
	public void keyReleased(KeyEvent e) {
		
	}

	@Override
	public void keyTyped(KeyEvent e) {
		
		e.consume();
		
		if(Character.isDigit(e.getKeyChar()) && '0' != e.getKeyChar() ){
			this.setText(Character.toString(e.getKeyChar()));
			Sudoku.check(this);
		}
	}
	
	public void controle(textBox tb){
		if(!this.getText().equals("")){
			if (Integer.parseInt(this.getText()) == Integer.parseInt(tb.getText())  && !tb.equals(this)){
				setBackground(Color.RED);
			} else {
				setBackground(Color.WHITE);
			}
		}
	}
	
	public void noContruole(){
		setBackground(Color.WHITE);
	}
	
	public void isStandard(){
		setText(""+number);
		setEditable(false);
	}
	
	public void setNumber(int number){ this.number = number; }
	public int getNumber(){ return number; }
}
